<template>
	<view>
		<view :style="{height:navHeight+'px',backgroundColor:bgc}">
		</view>
		<view class="nav-container" :style="{top:navHeight+'px'}">
			<view class="left">
				<u-icon name="list" size="28" @click="goCategory"></u-icon>
			</view>
			<view class="center">
				<u-search placeholder="请输入宝贝名称" :showAction="false" :disabled="true" @click="goSearchPage"></u-search>
			</view>
			<view class="right">
				<u-icon name="account-fill" size="28"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"custom-nav-bar",
		props:{
			bgc:{
				type:String
			}
		},
		data() {
			return {
				navHeight:0
			};
		},
		methods:{
			getNavHeight(){
				//获取SystemInfo对象
				const systemInfo=uni.getSystemInfoSync();
				//获取状态栏的高度
				const statusBarHeight=systemInfo.statusBarHeight;
				console.log('状态栏高度',statusBarHeight);
			    //获取胶囊按钮对象
				const menuBtn=uni.getMenuButtonBoundingClientRect();
				this.navHeight=(menuBtn.top-statusBarHeight)*2+menuBtn.height+statusBarHeight
				
			},
			goCategory(){
				uni.navigateTo({
					url:'/pages/category/category'
				})
			},
			goSearchPage(){
				uni.navigateTo({
					url:'/pages/searchpage/searchpage'
				})
			}
		},
		mounted(){
			// #ifdef MP-WEIXIN
			this.getNavHeight();
			// #endif
		}
	}
</script>

<style lang="scss">
	.nav-container{
		box-sizing: border-box;
		@include flex-box(between,center,row);
		width: 750rpx;
		height: 100rpx;
		padding: 10rpx 20rpx;
		background-color: hsla(0,0%,100%,.5);
		position: fixed;
		z-index: 1;
	}
</style>